package com.neteast.bustruck.db.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.neteast.bustruck.db.entiys.User

/**
 * https://juejin.cn/post/7218743537495998524
 */
@Dao
interface UserDao {

    @Query("SELECT * FROM user")
    suspend fun getAll(): List<User>?

    @Query("SELECT * FROM user WHERE uid IN (:userIds)")
    suspend fun loadAllByIds(userIds: IntArray): List<User>?

    /**
     * 通过用户名来找寻制定用户
     */
    @Query("SELECT * FROM user WHERE username LIKE :name")
    suspend fun findByName( name: String): User?



    @Update
    suspend fun updateUser(vararg user: User):Int

    @Insert
   suspend fun insertUser( users: User):Long



    @Delete
   suspend fun delete(user: User):Int
}

